<?php
/**
* @package   auto_occasion
* @subpackage publicite
* @author    your name
* @copyright 2011 your name
* @link      http://www.yourwebsite.undefined
* @license    All rights reserved
*/

class BoPubCtrl extends jController {

public $pluginParams = array(
                                    '*'=>array('auth.required'=>true,
                                    'jacl2.right'=>'admin.compte.gerer'
                                    )
                            );
    /**
    * Liste des pub
    */
    function index() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_PUB ;
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jconfirmaction.jquery.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jconfirmaction.jquery.ask.js');

        jClasses::inc('publicite~pubSrv');
        $pub = pubSrv::liste();

        $rep->bodyTpl = 'publicite~BoPubList';
        
        $rep->body->assign('pub', $pub);

        return $rep;
    }

    /**
    * Ajout / modif d'un pub
    */
    function editer() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_PUB ;
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery.validation.js');



        jClasses::inc('publicite~pubSrv');
        jClasses::inc('commun~common');

        $id = $this->intParam('id', '');
        $pub   = ($id) ? pubSrv::chargeParId($id) : pubSrv::init();
        $emplacement   = pubSrv::listeEplacement();
        $rubrique      = common::liste('ao_pub_rubrique');

        $rep->body->assign('pub', $pub);
        $rep->body->assign('emplacement', $emplacement);
        $rep->body->assign('rubrique', $rubrique);

        $rep->bodyTpl = 'publicite~BoPubEdit';
		
        

        return $rep;
    }

    /**
     * Enregistrer un pub
     *
     *
     */
     function sauvegarder() {

        jClasses::inc("publicite~pubSrv");

        $id                = $this->intParam ('id', 0);
        $params            = $this->params();

        if ($id) {
            pubSrv::modifier($params);
        } else {
            pubSrv::ajouter($params);
        }

        $rep = $this->getResponse('redirect');
        $rep->action = 'publicite~BoPub:index';
        return $rep;
    }

     /**
    * Supprimer une categorie
    */
    function supprimer() {
        $rep = $this->getResponse('redirect');

        jClasses::inc('publicite~pubSrv');
        $id = $this->intParam('id', '');
        pubSrv::supprimer($id);

        $rep->action = 'publicite~BoPub:index';

        return $rep;
    }



}

